home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TEXTFILE.SWG / 0009_SCROLLER.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  95 lines

  1. {
  2. ERIC MILLER
  3. read a Text File and scroll
  4. }
  5.  
  6. Uses
  7.   Crt;
  8.  
  9. Const
  10.   MaxLine   = 200;
  11.   MaxLength = 80;
  12.  
  13. Var
  14.   Lines       : Array [1..MaxLine] of String[MaxLength];
  15.   OldLine,
  16.   L,
  17.   CurrentLine,
  18.   NumLines    : Word;
  19.   TextFile    : Text;
  20.   Key         : Char;
  21.   Redraw,
  22.   Done        : Boolean;
  23.  
  24. begin
  25.   ClrScr;
  26.   Assign(TextFile, 'MCGALIB.PAS');
  27.   Reset(TextFile);
  28.   NumLines := 0;
  29.   While not EOF(TextFile) and (NumLines < MaxLine) DO
  30.   begin
  31.     Inc(NumLines);
  32.     Readln(TextFile, Lines[NumLines]);
  33.   end;
  34.   Close(TextFile);
  35.  
  36. {
  37.  Well...that handles getting the File into memory...but
  38.  to scroll through using Up/Down & PgUp PgDn is a lot harder,
  39.  but not incredibly difficult.
  40. }
  41.   Done := False;
  42.   Redraw := True;
  43.   CurrentLine := 1;
  44.  
  45.   While not Done DO
  46.   begin
  47.     if Redraw then
  48.     begin
  49.       GotoXY(1,1);
  50.       For L := CurrentLine to CurrentLine + 22 DO
  51.           Write(Lines[L], ' ':(80-Length(Lines[L])));
  52.       Redraw := False;
  53.     end;
  54.     Key := ReadKey;
  55.     Case Key of
  56.       #0:
  57.         begin { cursor/page keys }
  58.           OldLine := CurrentLine;
  59.           Key := ReadKey;
  60.  
  61.           Case Key of
  62.             #72: { up  }
  63.               if CurrentLine > 1 then
  64.                 Dec(CurrentLine);
  65.             #80: { down  }
  66.               if CurrentLine < (NumLines-22) then
  67.                 Inc(CurrentLine);
  68.             #73: { page up  }
  69.               if CurrentLine > 23 then
  70.                 Dec(CurrentLine, 23)
  71.               else
  72.                 CurrentLine := 1;
  73.             #81: { page down }
  74.                if CurrentLine < (NumLines-44) then
  75.                  Inc(CurrentLine, 23)
  76.                else
  77.                  CurrentLine := NumLines-22;
  78.           end;
  79.  
  80.           if CurrentLine <> OldLine then
  81.             Redraw := True;
  82.         end;
  83.  
  84.       #27: Done := True;
  85.  
  86.     end; {Case}
  87.   end; {begin}
  88. end. {Program}
  89.  
  90. {
  91. That should work For scrolling through the lines. Sorry
  92. 'bout not commenting the code alot; it is almost self-explanatory
  93. though.  But it works!  You could optimize it For larger Files
  94. by using an Array of Pointers to Strings.  But enough For now.
  95. }